home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Online / hsc / source / hsclib / linit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-02  |  18.0 KB  |  651 lines

  1. /*
  2.  * This source code is part of hsc, a html-preprocessor,
  3.  * Copyright (C) 1995-1997  Thomas Aglassinger
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  */
  20. /*
  21.  * hsclib/linit.c
  22.  *
  23.  * functions to init & read preferences for a hsc-process
  24.  *
  25.  * updated: 15-Apr-1997
  26.  * created: 19-Feb-1996
  27.  */
  28.  
  29. #include "hsclib/inc_base.h"
  30.  
  31. #include "hsclib/defattr.h"
  32. #include "hsclib/deftag.h"
  33. #include "hsclib/include.h"
  34. #include "hsclib/parse.h"
  35.  
  36. #include "hsclib/tag_a.h"
  37. #include "hsclib/tag_hsc.h"
  38. #include "hsclib/tag_if.h"
  39. #include "hsclib/tag_macro.h"
  40. #include "hsclib/tag_misc.h"
  41.  
  42. #include "ugly/fname.h"
  43.  
  44. #if DEBUG
  45. /*
  46.  * debugging print functions
  47.  */
  48. static VOID prt_ent(FILE * stream, APTR data)
  49. {
  50.     HSCENT *ent = (HSCENT *) data;
  51.  
  52.     if (ent)
  53.     {
  54.         fprintf(stream, " %s", ent->name);
  55.         if (ent->replace)
  56.             fprintf(stream, "=%s", ent->replace);
  57.         if (ent->numeric)
  58.             fprintf(stream, "=%ld", ent->numeric);
  59.     }
  60.     else
  61.         fprintf(stream, " <NULL>");
  62. }
  63.  
  64. static VOID prt_tag(FILE * stream, APTR data)
  65. {
  66.     if (data)
  67.     {
  68.         HSCTAG *tag = (HSCTAG *) data;
  69.         fprintf(stream, " <");
  70.         if (tag->option & HT_CLOSE)
  71.             fprintf(stream, "/");
  72.         if (tag->o_handle)
  73.             fprintf(stderr, "*");
  74.         fprintf(stream, "%s", tag->name);
  75.         if (tag->c_handle)
  76.             fprintf(stderr, "*");
  77.         if (tag->option & HT_REQUIRED)
  78.             fprintf(stream, "/r");
  79.         if (tag->option & HT_RECOMMENDED)
  80.             fprintf(stream, "/rcmd");
  81.         if (tag->option & HT_ONLYONCE)
  82.             fprintf(stream, "/1");
  83.         if (tag->option & HT_AUTOCLOSE)
  84.             fprintf(stream, "/sc");
  85.         if (tag->option & HT_SPECIAL)
  86.             fprintf(stream, "/a");
  87.         fprintf(stream, ">");
  88.     }
  89.     else
  90.         fprintf(stream, " <NULL>");
  91. }
  92. #endif
  93.  
  94. /* function to temporarily disable debuggin output */
  95. #if 1
  96. static BOOL dbg_old = FALSE;
  97.  
  98. #define dbg_disable(hp) {dbg_old = hp->debug; hp->debug=FALSE;}
  99. #define dbg_restore(hp) {hp->debug=dbg_old;}
  100.  
  101. #else
  102. #define dbg_disable(hp)
  103. #define dbg_restore(hp)
  104. #endif
  105.  
  106. /*
  107.  * find_prefs_fname
  108.  *
  109.  * find preferences file: first check, if it is located
  110.  * somewhere in the paths given via CONFIG_PATH (which
  111.  * is a system depandent symbol); if not, check if it
  112.  * is in the path described in the envvar HSCPREFS
  113.  *
  114.  * result: full path & filename of prefs or NULL if not found
  115.  *
  116.  * TODO: This routine sucks because of the static cfgfn[];
  117.  *       instead a hp->prefs_fname should be used
  118.  */
  119. static STRPTR find_prefs_fname(HSCPRC * hp)
  120. {
  121. #define ENV_HOME "HOME"
  122.     STRPTR prefs_fname = NULL;
  123.     STRPTR paths[] =            /* paths to search for config file */
  124.     {"", "", "", CONFIG_PATH,
  125.      NULL, NULL};
  126.     STRPTR path = NULL;
  127.     UBYTE path_ctr = 0;
  128.     FILE *cfgf = NULL;          /* prefs file */
  129.     EXPSTR *hscpathstr = init_estr(32);         /* buffer to read $HSCPATH */
  130.     EXPSTR *homepathstr = init_estr(32);        /* buffer to read $HOME */
  131.  
  132.     static STRARR cfgfn[300];   /* TODO: expstr; buffer to create
  133.                                  *   filename of config file */
  134.  
  135.     /* add "$HSCPATH/hsc.prefs" to files-to-be-checked */
  136.     if (link_envfname(hscpathstr, ENV_HSCPATH, NULL, NULL))
  137.     {
  138.         /* add envval to paths */
  139.         paths[1] = estr2str(hscpathstr);
  140.     }
  141.  
  142.     /* add "$HOME/lib/hsc.prefs" to files-to-be-checked */
  143.     if (link_envfname(homepathstr, ENV_HOME, "lib", NULL))
  144.     {
  145.         /* add envval to paths */
  146.         paths[2] = estr2str(homepathstr);
  147.     }
  148.  
  149.     /* try to open any prefs-file */
  150.     do
  151.     {                           /* loop: */
  152.         path = paths[path_ctr]; /*   get next path */
  153.         if (path)
  154.         {                       /*   is it the last one? */
  155.             strcpy(cfgfn, path);        /*   N->generate filename */
  156.             strcat(cfgfn, CONFIG_FILE);
  157.  
  158.             DC(fprintf(stderr, DHL "try \"%s\"\n", cfgfn));
  159.  
  160.             cfgf = fopen(cfgfn, "r");   /*      try to open file */
  161.         }
  162.         path_ctr++;             /*   process next path */
  163.     }
  164.     while (path && (!cfgf));    /* until no path left or file opened */
  165.  
  166.     if (cfgf)
  167.     {
  168.         prefs_fname = cfgfn;
  169.         fclose(cfgf);
  170.     }
  171.  
  172.     del_estr(homepathstr);
  173.     del_estr(hscpathstr);
  174.  
  175.     return (prefs_fname);
  176. }
  177.  
  178. #if 0
  179. /*
  180.  * hsc_read_base_info
  181.  *
  182.  * try to open base-file and read where in memory
  183.  * information about defined tags/attributes/entities
  184.  * is located.
  185.  *
  186.  * result: dummy-hsc-process that only contains
  187.  *   the information read from base-file
  188.  *
  189.  * see "LoadHscPrefs/LoadHscPrefs.c"
  190.  */
  191. HSCPRC *hsc_read_base_info(VOID)
  192. {
  193.     HSCPRC *dummy_hp = NULL;
  194.  
  195. #ifdef HSCBASE_FILE
  196.  
  197.     FILE *inpf = fopen(HSCBASE_FILE, "r");
  198.     DLLIST *hp_deftag = NULL;
  199.     DLLIST *hp_defattr = NULL;
  200.     DLLIST *hp_defent = NULL;
  201.  
  202.     if (inpf)
  203.     {
  204.         STRARR s[32];
  205.         APTR p = NULL;
  206.  
  207.         while (fscanf(inpf, "%s %p\n", &(s[0]), &p) != EOF)
  208.         {
  209.             if (!strcmp("DEFTAG", s))
  210.             {
  211.                 hp_deftag = (DLLIST *) p;
  212.                 printf(DHL "deftag  %p\n", hp_deftag);
  213.             }
  214.             else if (!strcmp("DEFATTR", s))
  215.             {
  216.                 hp_defattr = (DLLIST *) p;
  217.                 printf(DHL "defattr %p\n", hp_defattr);
  218.             }
  219.             else if (!strcmp("DEFENT", s))
  220.             {
  221.                 hp_defent = (DLLIST *) p;
  222.                 printf(DHL "defent  %p\n", hp_defent);
  223.             }
  224.             else
  225.             {
  226.                 printf(DHL "%s %p (unknown)\n", s, p);
  227.             }
  228.         }
  229.     }
  230.  
  231.     fclose(inpf);
  232.  
  233.     if (hp_deftag && hp_defattr && hp_defent)
  234.     {
  235.         /* assign information to dummy-process */
  236.         dummy_hp = new_hscprc();
  237.  
  238.         del_dllist(dummy_hp->defattr);
  239.         del_dllist(dummy_hp->defent);
  240.         del_dllist(dummy_hp->deftag);
  241.  
  242.         dummy_hp->deftag = hp_deftag;
  243.         dummy_hp->defattr = hp_defattr;
  244.         dummy_hp->defent = hp_defent;
  245.  
  246.         /* assign new del_data-methodes */
  247.         dummy_hp->defattr->del_data = del_hscattr;
  248.         dummy_hp->defent->del_data = del_entity;
  249.         dummy_hp->deftag->del_data = del_hsctag;
  250.     }
  251.  
  252. #endif
  253.     return (dummy_hp);
  254. }
  255.  
  256. BOOL hsc_copy_base_info(HSCPRC * dest_hp, HSCPRC * dummy_hp)
  257. {
  258.     DLNODE *nd = dummy_hp->deftag->first;
  259.  
  260.     /* copy defined tags */
  261.     while (nd)
  262.     {
  263.         HSCTAG *newtag = cpy_hsctag((HSCTAG *) nd->data);
  264.         app_dlnode(dest_hp->deftag, (APTR) newtag);
  265.         nd = nd->next;
  266.     }
  267.  
  268.     return (TRUE);
  269. }
  270. #endif
  271.  
  272. /*
  273.  * hsc_read_prefs
  274.  *
  275.  * try to open (any) config file and read preferences
  276.  * from it
  277.  */
  278. BOOL hsc_read_prefs(HSCPRC * hp, STRPTR prefs_fname)
  279. {
  280.     BOOL ok = FALSE;
  281.  
  282.     /* find prefs file */
  283.     if (!prefs_fname)
  284.         prefs_fname = find_prefs_fname(hp);
  285.  
  286.     /* status message */
  287.     if (prefs_fname)
  288.     {
  289.         dbg_disable(hp);
  290.  
  291.         hsc_status_file_begin(hp, prefs_fname);
  292.         ok = hsc_include_file(hp, prefs_fname,
  293.                               IH_PARSE_HSC | IH_NO_STATUS);
  294.         dbg_restore(hp);
  295.  
  296.         if (ok)
  297.         {
  298.             EXPSTR *msg = init_estr(32);
  299.             set_estr(msg, prefs_fname);
  300.             app_estr(msg, ": preferences read");
  301.             hsc_status_misc(hp, estr2str(msg));
  302.             del_estr(msg);
  303.         }
  304.     }
  305.     else
  306.     {
  307.         hsc_message(hp, MSG_NO_CONFIG,
  308.                     "can not open preferences file");
  309.     }
  310.  
  311.     return (ok);
  312. }
  313.  
  314. /*
  315.  * callback to display "project-file corrupt"-message
  316.  */
  317. static VOID msg_corrupt_pf(HSCPRJ * project, STRPTR reason)
  318. {
  319.     STRPTR prjtxt = "project-file corrupt";
  320.     HSCPRC *hp = (HSCPRC *) project->user_data;
  321.  
  322.     if (reason)
  323.         hsc_message(hp, MSG_CORRUPT_PRJFILE, "%s (%s)", prjtxt, reason);
  324.     else
  325.         hsc_message(hp, MSG_CORRUPT_PRJFILE, "%s", prjtxt);
  326. }
  327.  
  328. /*
  329.  * hsc_init_project
  330.  *
  331.  * read project-file
  332.  */
  333. BOOL hsc_init_project(HSCPRC * hp, STRPTR project_fname)
  334. {
  335.     BOOL ok = FALSE;
  336.  
  337.     /* init project */
  338.     hp->project = new_project();
  339.     hp->project->user_data = (APTR) hp;
  340.     hp->project->debug = hp->debug;
  341.     hp->project->CB_msg_corrupt_pf = msg_corrupt_pf;
  342.  
  343.     if (project_fname)
  344.     {
  345.         /*
  346.          * read project-data
  347.          */
  348.         D(fprintf(stderr, DHL "read project-file `%s'\n", project_fname));
  349.  
  350.         hsc_status_file_begin(hp, project_fname);
  351.  
  352.         /* read project-file */
  353.         hp->inpf = infopen(project_fname, 0);
  354.  
  355.         if (hp->inpf)
  356.         {
  357.             ok = hsc_project_read_data(hp->project, hp->inpf);
  358.             infclose(hp->inpf);
  359.             if (ok)
  360.             {
  361.                 /* message about success */
  362.                 EXPSTR *msg = init_estr(32);
  363.                 set_estr(msg, project_fname);
  364.                 app_estr(msg, ": project-file read");
  365.                 hsc_status_misc(hp, estr2str(msg));
  366.                 del_estr(msg);
  367.             }
  368.  
  369.             hp->inpf = NULL;
  370.         }
  371.         else
  372.         {
  373.             D(fprintf(stderr, DHL "  can't read project-file\n"));
  374.             ok = TRUE;
  375.             /* TODO: message "creating new one" */
  376.         }
  377.     }
  378.     else
  379.     {
  380.         D(fprintf(stderr, DHL "no project-file to load\n"));
  381.         ok = TRUE;
  382.     }
  383.  
  384.     if (ok)
  385.     {
  386.         /* dettach current document */
  387.         hsc_project_set_document(hp->project, hp->filename_document);
  388.     }
  389.  
  390.     return (ok);
  391. }
  392.  
  393. /*
  394.  * hsc_set_tagCB
  395.  */
  396. VOID hsc_set_tagCB(HSCPRC * hp, STRPTR name,
  397.                    BOOL(*op_hnd) (HSCPRC * inpf, HSCTAG * tag),
  398.                    BOOL(*cl_hnd) (HSCPRC * inpf, HSCTAG * tag))
  399. {
  400.     HSCTAG *tag = find_strtag(hp->deftag, name);
  401.  
  402.     if (tag && !(tag->option & HT_NOHANDLE))
  403.     {
  404.         /* set handles */
  405.         DC(fprintf(stderr, DHL "add handles for <%s> (%p,%p)\n",
  406.                    name, op_hnd, cl_hnd));
  407.         tag->o_handle = op_hnd;
  408.         tag->c_handle = cl_hnd;
  409.     }
  410. }
  411.  
  412. /*
  413.  * init_hsctags
  414.  *
  415.  * define hsc tags & attributes; assign tagCBs for them
  416.  *
  417.  * NOTE: this ones tricky, but a bit perverted somehow
  418.  */
  419. BOOL hsc_init_tagsNattr(HSCPRC * hp)
  420. {
  421. #define INCLUDE_ATTR " PRE:bool SOURCE:bool TEMPORARY:bool" \
  422.                      " INDENT:num TABSIZE:num=\"4\" "
  423.     BYTE i = 0;
  424.     BOOL ok = TRUE;
  425.     BOOL open_tag;
  426.     HSCTAG *tag;
  427.  
  428.     /* define hsc internal tags */
  429.     STRPTR hsc_prefs[] =
  430.     {
  431.     /* tags with special chars as name
  432.      *
  433.      * IMPORTANT: When adding new tags with names not starting with
  434.      *   HSC_TAGID, make sure to update `tag.c:is_hsc_tag()'
  435.      */
  436.         HSC_COMMENT_STR " /SKIPLF /SPECIAL>",
  437.         HSC_VERBATIM_STR" /SPECIAL>",
  438.         HSC_INSEXPR_STR " /SPECIAL>",
  439.     /* tags starting with HSC_TAGID */
  440.         HSC_CONTENT_STR " /SKIPLF>",
  441.         HSC_DEFENT_STR " /SKIPLF NAME:string/r RPLC:string NUM:num>",
  442.         HSC_DEFICON_STR " /SKIPLF NAME:string/r>",
  443.         HSC_DEFINE_STR " /SKIPLF /SPECIAL>",
  444.         HSC_DEFTAG_STR " /SKIPLF /SPECIAL>",
  445.         HSC_DEPEND_STR " /SKIPLF ON:string/r FILE:bool>",
  446.         HSC_ELSE_STR " /SKIPLF /MBI=\"" HSC_IF_STR "\">",
  447.         HSC_ELSEIF_STR " /SKIPLF /MBI=\"" HSC_IF_STR "\"" CONDITION_ATTR ":bool>",
  448.         HSC_MESSAGE_STR " /SKIPLF TEXT:string/r CLASS:enum(\"note|warning|error|fatal\")='note'>",
  449.         HSC_EXEC_STR " /SKIPLF COMMAND:string/r REMOVE:enum(\"on|off|auto\")=\"auto\" ATTRIBUTE:string INCLUDE:bool FILE:string " INCLUDE_ATTR ">",
  450.         HSC_EXPORT_STR " /SKIPLF FILE:string/r DATA:string/r APPEND:bool>",
  451.         HSC_IF_STR " /SKIPLF /CLOSE " CONDITION_ATTR ":bool>",
  452.         HSC_INSERT_STR " /OBSOLETE TEXT:string TIME:bool FORMAT:string>",
  453.         HSC_INCLUDE_STR " /SKIPLF FILE:string/r " INCLUDE_ATTR ">",
  454.         HSC_LAZY_STR " /SKIPLF /SPECIAL>",
  455.         HSC_LET_STR " /SKIPLF /SPECIAL>",
  456.         HSC_MACRO_STR " /SKIPLF /SPECIAL>",
  457.         HSC_SOURCE_STR " /SKIPLF PRE:bool>",
  458.         HSC_STRIPWS_STR " TYPE:enum(\"" STRIPWS_ENUM "\")=\"" STRIPWS_BOTH "\">",
  459.         NULL
  460.     };
  461.  
  462.     STRPTR hsc_attribs[] =
  463.     {
  464.     /*
  465.      * define hsc attributes
  466.      */
  467.      /* name                 : type     : default value */
  468.         SYSTEM_ATTR         ":string/c" , SYSTEM_ATTR_ID,
  469.         ANCHOR_ATTR         ":string"   , "this is a feature, not a bug",
  470.         CONTENT_ATTR        ":string/c" , NULL,
  471.         RESULT_ATTR         ":num=\"0\"", NULL, /* a bit strange */
  472.         FILESIZEFORMAT_ATTR ":string"   , "%a%u",
  473.         TIMEFORMAT_ATTR     ":string"   , "%d-%b-%Y, %H:%M",
  474.         LINEFEED_ATTR       ":string>"  , NULL,
  475.         NULL, NULL};
  476.  
  477.     /* temporarily disable debugging output */
  478.     dbg_disable(hp);
  479.  
  480.     /* define hsc-tags */
  481.     i = 0;
  482.     while (!(hp->fatal) && hsc_prefs[i])
  483.     {
  484.         STRARR infname[20];
  485.  
  486.         sprintf(infname, SPECIAL_FILE_ID "init%3d", i);
  487.         hp->inpf = infopen_str(infname, hsc_prefs[i], 60);
  488.  
  489.         if (hp->inpf)
  490.         {
  491.             tag = def_tag_name(hp, &open_tag);
  492.             ok = (tag && def_tag_args(hp, tag));
  493.             infclose(hp->inpf);
  494.         }
  495.  
  496.         i++;
  497.     }
  498.  
  499.     /* init hsc-attributes */
  500.     i = 0;
  501.     while (!(hp->fatal) && hsc_attribs[i])
  502.     {
  503.         define_attr_by_text(hp, hsc_attribs[i], hsc_attribs[i+1], 0);
  504.         i+=2;
  505.     }
  506.  
  507.     /* assign "\n" to linefeed-attribute */
  508.     set_vartext(find_varname(hp->defattr, LINEFEED_ATTR), "\n");
  509.  
  510.     /* assign tag-callbacks to hsc-tags */
  511.     if (ok)
  512.     {
  513.         hsc_set_tagCB(hp, HSC_COMMENT_STR, handle_hsc_comment, NULL);
  514.         hsc_set_tagCB(hp, HSC_CONTENT_STR, handle_hsc_content, NULL);
  515.         hsc_set_tagCB(hp, HSC_DEFENT_STR, handle_hsc_defent, NULL);
  516.         hsc_set_tagCB(hp, HSC_DEFICON_STR, handle_hsc_deficon, NULL);
  517.         hsc_set_tagCB(hp, HSC_DEFINE_STR, handle_hsc_define, NULL);
  518.         hsc_set_tagCB(hp, HSC_DEFTAG_STR, handle_hsc_deftag, NULL);
  519.         hsc_set_tagCB(hp, HSC_DEPEND_STR, handle_hsc_depend, NULL);
  520.         hsc_set_tagCB(hp, HSC_ELSE_STR, handle_hsc_else, NULL);
  521.         hsc_set_tagCB(hp, HSC_ELSEIF_STR, handle_hsc_elseif, NULL);
  522.         hsc_set_tagCB(hp, HSC_EXEC_STR, handle_hsc_exec, NULL);
  523.         hsc_set_tagCB(hp, HSC_EXPORT_STR, handle_hsc_export, NULL);
  524.         hsc_set_tagCB(hp, HSC_IF_STR, handle_hsc_if, handle_hsc_cif);
  525.         hsc_set_tagCB(hp, HSC_INCLUDE_STR, handle_hsc_include, NULL);
  526.         hsc_set_tagCB(hp, HSC_INSERT_STR, handle_hsc_insert, NULL);
  527.         hsc_set_tagCB(hp, HSC_INSEXPR_STR, handle_hsc_insert_expression, NULL);
  528.         hsc_set_tagCB(hp, HSC_COMMENT_STR, handle_hsc_comment, NULL);
  529.         hsc_set_tagCB(hp, HSC_LAZY_STR, handle_hsc_lazy, NULL);
  530.         hsc_set_tagCB(hp, HSC_LET_STR, handle_hsc_let, NULL);
  531.         hsc_set_tagCB(hp, HSC_MACRO_STR, handle_hsc_macro, NULL);
  532.         hsc_set_tagCB(hp, HSC_MESSAGE_STR, handle_hsc_message, NULL);
  533.         hsc_set_tagCB(hp, HSC_VERBATIM_STR, handle_hsc_verbatim, NULL);
  534.         hsc_set_tagCB(hp, HSC_SOURCE_STR, handle_hsc_source, NULL);
  535.         hsc_set_tagCB(hp, HSC_STRIPWS_STR, handle_hsc_stripws, NULL);
  536.     }
  537.  
  538.     /* restore debugging output */
  539.     dbg_restore(hp);
  540.  
  541.     return (ok);
  542. }
  543.  
  544. /*
  545.  * hsc_init_basicEntities
  546.  *
  547.  * create basic entities (&, >, <, ")
  548.  * (should be called BEFORE hsc_read_prefs())
  549.  */
  550. BOOL hsc_init_basicEntities(HSCPRC * hp)
  551. {
  552.     BOOL ok = TRUE;
  553.  
  554.     /* entities */
  555.     ok &= add_ent(hp->defent, "amp", NULL, 0);  /* & */
  556.     ok &= add_ent(hp->defent, "lt", NULL, 0);   /* < */
  557.     ok &= add_ent(hp->defent, "gt", NULL, 0);   /* > */
  558.     ok &= add_ent(hp->defent, "quot", NULL, 0);         /* q */
  559.  
  560.     return (ok);
  561. }
  562.  
  563. /*
  564.  * hsc_assign_tagCBs
  565.  *
  566.  * assign tag-callbacks to standard html-tags
  567.  * (MUST ONLY be called AFTER hsc_read_prefs())
  568.  */
  569. BOOL hsc_assign_tagCBs(HSCPRC * hp)
  570. {
  571.     hsc_set_tagCB(hp, "!", handle_sgml_comment, NULL);
  572.     hsc_set_tagCB(hp, "A", handle_anchor, handle_canchor);
  573.     hsc_set_tagCB(hp, "BASE", handle_base, NULL);
  574.     hsc_set_tagCB(hp, "BLINK", handle_blink, NULL);
  575.     hsc_set_tagCB(hp, "H1", handle_heading, NULL);
  576.     hsc_set_tagCB(hp, "H2", handle_heading, NULL);
  577.     hsc_set_tagCB(hp, "H3", handle_heading, NULL);
  578.     hsc_set_tagCB(hp, "H4", handle_heading, NULL);
  579.     hsc_set_tagCB(hp, "H5", handle_heading, NULL);
  580.     hsc_set_tagCB(hp, "H6", handle_heading, NULL);
  581.     hsc_set_tagCB(hp, "IMG", handle_img, NULL);
  582.     hsc_set_tagCB(hp, "PRE", handle_pre, handle_end_pre);
  583.  
  584.     return (TRUE);
  585. }
  586.  
  587. /*
  588.  * hsc_init_hscprc
  589.  *
  590.  * - init all items of hsc-process
  591.  * - create hsc-tags & special atttributes
  592.  * - read preferences file
  593.  * - assign tag-callbacks
  594.  */
  595. BOOL hsc_init_hscprc(HSCPRC * hp, STRPTR prefs_fname)
  596. {
  597.     BOOL ok = FALSE;            /* return value */
  598.  
  599.     if (hsc_init_tagsNattr(hp)
  600.         && hsc_init_basicEntities(hp)
  601.         && hsc_read_prefs(hp, prefs_fname)
  602.         && hsc_assign_tagCBs(hp)
  603.         )
  604.     {
  605.         /* return sucess */
  606.         ok = TRUE;
  607.  
  608.         /* printf list of defined tags & entities */
  609.         DC(
  610.               {
  611.               DLNODE * nd;
  612.               HSCENT * ent;
  613.  
  614.               nd = hp->defent->first;
  615.               if (nd)
  616.               {
  617.               fprintf(stderr, DHL "Known entities:");
  618.  
  619.               while (nd)
  620.               {
  621.               ent = (HSCENT *) nd->data;
  622.               fprintf(stderr, " &%s;", ent->name);
  623.               nd = nd->next;
  624.               }
  625.               fprintf(stderr, "\n");
  626.               }
  627.  
  628.               nd = hp->deftag->first;
  629.               if (nd)
  630.               {
  631.               fprintf(stderr, DHL "Known tags:");
  632.               while (nd)
  633.               {
  634.               prt_tag(stderr, nd->data);
  635.               nd = nd->next;
  636.               }
  637.               fprintf(stderr, "\n");
  638.               }
  639.  
  640.               }
  641.         );                      /* DC */
  642.     }
  643.  
  644.     hp->click_here_str =
  645.         get_vartext_byname(hp->defattr, CLICK_HERE_ATTR);
  646.     hp->color_names =
  647.         get_vartext_byname(hp->defattr, COLOR_NAMES_ATTR);
  648.  
  649.     return (ok);
  650. }
  651.